<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>选择时间查询车辆信息</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
            /* 添加背景图片 */
            background-image: url('../images/停车场图片.png');
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
        }

      .container {
            background-color: #fff; /* 设置为完全不透明的白色 */
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 400px;
        }

      .title {
            text-align: center;
            margin-bottom: 20px;
            color: #00008B; /* 深蓝色 */
            font-weight: bold; /* 加粗 */
        }

      .form-group {
            margin-bottom: 15px;
        }

      .form-group label {
            display: block;
            margin-bottom: 5px;
            color: #555;
        }

      .form-group input,
      .form-group select {
            width: 100%;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
        }

      .form-group button {
            width: 100%;
            padding: 10px;
            background-color: #007BFF;
            color: #fff;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

      .form-group button:hover {
            background-color: #0056b3;
        }

      .message {
            /* 这里虽然保留了message类，但后续不会在页面上显示消息 */
            text-align: center;
            margin-top: 15px;
            color: green;
        }

        /* 新增返回按钮样式 */
      .return-button {
            margin-top: 15px;
            padding: 8px 16px;
            background-color: #007BFF;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

      .return-button:hover {
            background-color: #0056b3;
        }
    </style>
</head>

<body>
<div id="appTime">
    <div class="container">
        <h2 class="title">选择时间查询车辆信息</h2>
        <form id="selectParkForm">
            <div class="form-group">
                <label for="timeSelect">请输入时间范围</label>
                <input type="text" id="timeSelect" v-model="time" name="time" placeholder="请输入时间范围" required>
            </div>
            <div class="form-group">
                <!-- 使用 @click 事件触发 doCheckCarId -->
                <button type="button" @click="doCheckCarId">查询</button>
            </div>
        </form>

        <!-- 查询结果展示区域 -->
        <br/>
        <label :style="{color: tipsColor}">{{ checkTips }}</label>

        <!-- 车牌信息显示区域 -->
        <div id="parkingInfo" v-if="timeDetails" style="display:block;">
            <h3>车位信息</h3>
            <p><strong>车牌ID:</strong> {{ timeDetails.carId }}</p>
            <p><strong>座位ID:</strong> {{ timeDetails.seatId }}</p>
            <p><strong>类型:</strong> {{ timeDetails.type }}</p>
            <p><strong>时间:</strong> {{ timeDetails.time }}</p>
        </div>

        <br/>
        <!-- 返回按钮 -->
        <button class="return-button" onclick="window.location.href = 'parkingvehicle.html'">返回</button>
    </div>
</div>

<script src="../layui/layui.js" type="text/javascript"></script>
<script src="../js/vue.js" type="text/javascript"></script>
<script src="../js/jquery-3.6.0.min.js" type="text/javascript"></script>

<script type="text/javascript">
let vm = new Vue({
    el: "#appTime",
    data: {
        time: "", // 用户输入的时间
        checkTips: "", // 查询提示
        tipsColor: "", // 提示颜色
        timeDetails: null // 用于存储返回的车位信息
    },
    methods: {
        // 正则表达式用于验证时间格式
        validateTimeFormat(time) {
            // 匹配格式 yyyy-MM-dd HH:mm:ss
            const timePattern = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/;
            return timePattern.test(time);
        },

        doCheckCarId() {
            let time = this.time;

            // 检查时间格式是否有效
            if (!this.validateTimeFormat(time)) {
                this.checkTips = "时间格式无效，正确格式为：yyyy-MM-dd HH:mm:ss";
                this.tipsColor = "red";
                this.timeDetails = null;
                return; // 如果格式无效，停止后续的请求
            }

            // 构造请求 URL
            let url = "http://localhost:8080/car/select_time";
            
            // 请求参数
            let params = { time: time };

            // 发起 GET 请求
            $.get(url, params, (res) => {
                // 输出验证结果
                console.log('接口返回数据:', res);
                if (res.data && typeof res.data === 'object') {
                    this.timeDetails = res.data;
                    this.checkTips = res.msg;
                    this.tipsColor = "green";
                } else {
                    this.checkTips = res.msg;
                    this.tipsColor = "red";
                    this.timeDetails = null;
                }
            }, "JSON");
        }
    }
});
</script>
</body>




</html>